/*
 * Phase.cpp
 *
 *  Created on: 23 May 2011
 *      Author: allan
 */

#include "Phase.h"

// GeoReact includes
#include "AqueousSolution.h"
#include "GaseousSolution.h"
#include "MineralSolution.h"

Phase::Phase()
{}

void Phase::SetPhaseName(const String& phase_name)
{
	this->phaseName = phase_name;
}

void Phase::SetSpecies(const StringVector& species)
{
	this->species = species;
}

void Phase::SetActivityFunction(const ActivityFunction& activity_function)
{
	this->activityFunction = activity_function;
}

const String& Phase::GetPhaseName() const
{
	return phaseName;
}

const StringVector& Phase::GetSpecies() const
{
	return species;
}

const Phase::ActivityFunction& Phase::GetActivityFunction() const
{
	return activityFunction;
}

const DoubleVector Phase::Activities(double T, double P, const DoubleVector& n) const
{
	return activityFunction(T, P, n);
}

template<class GenericSolution>
const Phase CreateGenericPhase(const GenericSolution& solution, const String& phaseName)
{
	Phase phase;
	
	Phase::ActivityFunction activityFunc = std::bind(&GenericSolution::Activities, solution, _1, _2, _3);
	
	phase.SetPhaseName(phaseName);
	phase.SetSpecies(solution.GetSpecies());
	phase.SetActivityFunction(activityFunc);
	
	return phase;
}

const Phase Phase::CreateAqueousPhase(const StringVector& aqueousSpecies)
{
	return CreateGenericPhase(AqueousSolution(aqueousSpecies), "AqueousPhase");
}

const Phase Phase::CreateGaseousPhase(const StringVector& gaseousSpecies)
{
	return CreateGenericPhase(GaseousSolution(gaseousSpecies), "GaseousPhase");
}

const Phase Phase::CreateMineralPhase(const StringVector& mineralSpecies)
{
	return CreateGenericPhase(MineralSolution(mineralSpecies), "MineralPhase");
}
